package com.epam.factories;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import com.epam.airlines.Airlines;
import com.epam.airlines.Engine;
import com.epam.airlines.Helicopter;
import com.epam.properties.PropertyFilePicker;

public class HelicopterFactory implements AbstractFactory {

	@Override
	public Helicopter createAircraft(int idPostfix) {
		Properties properties = new Properties();
		PropertyFilePicker filePicker = new PropertyFilePicker(
				TypeOfAircraft.HELICOPTER);
		try {
			properties.load(new FileInputStream(filePicker.randomFile()));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		String name = properties.getProperty("name");
		int numPass = Integer.valueOf(properties.getProperty("numPass"));
		float tonnage = Float.valueOf(properties.getProperty("tonnage"));
		int distance = Integer.valueOf(properties.getProperty("distance"));
		int consumption = Integer.valueOf(properties.getProperty("consumption"));
		String id = properties.getProperty("id")+idPostfix;
		Engine engine = Engine.valueOf(properties.getProperty("engine"));
		int tankVolume = Integer.valueOf(properties.getProperty("tankVolume"));
		Airlines.incTotals(numPass, tonnage);
		return new Helicopter(name, numPass, tonnage, distance, 
				consumption, id, engine, tankVolume);
	}

}
